﻿Ext.define('app.system.organization.Create',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    //maximized: true,
    width: 400,
    height: 300,
    layout: 'fit',
    parentNodeId: null,
    bodyStyle: 'padding:30px',
    initComponent: function () {
        var me = this;
        me.items = [me.getForm()];
        me.buttons = [
            { text: '保存', scope: this, handler: me.onSubmit },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    getForm: function () {
        var me = this;
        if (!this.form) {
            this.form = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                defaults: { anchor: '100%' },
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "right",
                    flex: 1,
                    margin: 6
                },
                items: [
                    {
                        fieldLabel: '组织结构',
                        allowBlank: false,
                        name: 'displayName'
                    }
                ]
            });
        }
        return this.form;
    },
    onSubmit: function () {
        var me = this;
        var form = me.getForm().getForm();
        if (!form.isValid()) {
            return false;
        }
        var json = form.getValues();
        json.parentId = me.parentNodeId;
        App.AjaxPost('/api/services/app/OrganizationUnit/CreateOrganizationUnit', json, function () {
            me.fireEvent("savesuccess");
        });
    }
});